define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'supplier/index' + location.search,
                    add_url: 'user_team_price/add',
                   // edit_url: 'supplier/edit',
                    // del_url: 'supplier/del',
                    multi_url: 'user_team_price/multi',
                    import_url: 'user_team_price/import',
                    table: 'user_team_price',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('合伙人id')},
                        {
                            field: 'status',
                            title: __('id状态'),
                            searchList: {"1": __('启动中'), "2": __('已禁用')},
                            formatter: Table.api.formatter.status
                        },

                        {field: 'suppname', title: __('合伙人名称'), operate: 'LIKE'},

                        {field: 'suppname2', title: __('合伙人手机号'), operate: 'LIKE'},

                        {
                            field: 'status2',
                            title: __('合伙人类型'),
                            searchList: {"1": __('普通'), "2": __('精英'), "3": __('事业')},
                            formatter: Table.api.formatter.status
                        },

                        {field: 'suppname3', title: __('合伙收益权重比例'), operate: false},
                        {field: 'suppname4', title: __('合伙人总收益'), operate: false},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {field: 'suppname5', title: __('支付宝绑定手机号'), operate: false},
                        {field: 'suppname6', title: __('银行卡号'), operate: false},
                        {field: 'suppname7', title: __('银行卡绑定手机号'), operate: false},

                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [

                                {
                                    name: 'detail',
                                    title: __('修改'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'user_team_price/edit'
                                },


                            ],
                        }

                    ]
                ],
                search: false,
                showColumns: false,
                showToggle: false,
            });


            //删除配置
            $(document).on("click", ".btn-delcfg", function () {
                var id =$(this).parent().parent().children('td').eq(1).html();
                console.log(id);
                Layer.confirm(__('确定要禁用吗?'), {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    Backend.api.ajax({
                        url: "general/config/del",
                        data: {name: $(that).data("name")}
                    }, function () {
                        $(that).closest("tr").remove();
                        Layer.close(index);
                    });
                });

            });




            $("#exp").bind("click",function(){
                var options = table.bootstrapTable('getOptions');
                var search = options.queryParams({});
                var str=location.search+"&filter="+search.filter+"&op="+search.op;
                window.location.href = 'order/export'+str  ;
            });

            $(".datetimerange").attr("data-time-picker",true);

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {

            }
        }
    };
    return Controller;
});